# Makefile  -*- Makefile -*-
# Copyright 2008 Nothing, Inc., All rights reserved.
#
# Epsilon Testbed (eTestbed)

# include directories
#INCDIRS = -I. -I/usr/X11R6/include -I$(TOPSRCDIR)
INCDIRS = -iquote. -I$(TOPSRCDIR) -I$(TOPDIR)/include -I$(TOPDIR)/include/freetype2 -I/usr/X11R6/include 

# library dirs
#LIBDIRS = -L$(TOPSRCDIR)/lib $(LDEFS) -L/usr/X11R6/lib -L/usr/lib -L../Epsilon/
LIBDIRS = -L$(TOPDIR)/Dev -L$(TOPDIR)/lib -L/usr/lib


# libraries to link
#LIBS = -lepsilon -lX11 -lstdc++ -lc #-lGL -lGLU -lCg -lCgGL -lpng -ljpeg
LIBS = -lEpsilon -lstdc++ -lc -lfreetype -framework OpenGL -framework OpenAL #-lGL -lGLU -lCg -lCgGL -lpng -ljpeg


# optimizer flags
#OPT =				# no optimization or debugging
#OPT = $(OPT_DEBUG)		# debugging only
#OPT = $(OPT_OPT)		# standard optimization
#OPT = $(OPT_DEBUG) $(OPT_OPT)	# debugging and optimization
#OPT = $(OPT_MAXOPT)		# maximal optimization

# profiler flags
#PROF =				# no profiling
#PROF = $(PROF_ON)		# turn on profiling

# extra compiler definitions
XCPLUSDEFS = -fPIC -DDO_NOT_USE_HTTPD 

# source, object files
SRCS := $(wildcard *.cpp */*.cpp prototype/eHTTP/*.cpp)
INLS := $(wildcard *.i)
INCS := $(wildcard *.h)
LOGS := $(patsubst %.log,"%.log" ,$(wildcard *.log))
OBJS := $(patsubst %.cpp,%.o,$(SRCS))

# target files
BIN_TARGET := eTestbed

# anything that this makefile can build
TARGETS := $(LOGS) $(OBJS) $(BIN_TARGET)

# all source files
SOURCES := $(SRCS) $(INCS) $(INLS)

# all doc files
DOCS := README

# standard Makefile targets

all: $(LOGS) $(BIN_TARGET)

checkin: checkin-local

clean: clean-local

depend: depend-local-c++

install: install-bin
 install-bin: $(BIN_TARGET)
	@$(ECHO) " INSTALL bin   "; /bin/cp $(BIN_TARGET) $(TOPDIR)/Dev $(LOG_MAKE)
#	mkdir $(TOPDIR)/Dev/$(BIN_TARGET).app;
#	mkdir $(TOPDIR)/Dev/$(BIN_TARGET).app/Contents;
#	mkdir $(TOPDIR)/Dev/$(BIN_TARGET).app/Contents/MacOS;
#	mkdir $(TOPDIR)/Dev/$(BIN_TARGET).app/Contents/MacOS/lib;
#	cp $(BIN_TARGET) $(TOPDIR)/Dev/$(BIN_TARGET).app/Contents/MacOS
#	cp $(TOPDIR)/Dev/libEpsilon.dylib $(TOPDIR)/Dev/$(BIN_TARGET).app/Contents/Frameworks
#	install_name_tool -change libEpsilon.dylib @executable_path/../Frameworks/libEpsilon.dylib $(TOPDIR)/Dev/$(BIN_TARGET).app/Contents/MacOS/eTestbed
#	cp $(TOPDIR)/Dev/lib/libfreetype.dylib $(TOPDIR)/Dev/$(BIN_TARGET).app/Contents/MacOS/lib

$(LOGS):
	@$(RM) -f $@

.SUFFIXES: .cpp
.cpp.o::
	@$(LOG_CPP_HEADER)
#	@$(ECHO) " CPP    $<"; $(CXX) $(CPLUSFLAGS) $(LDFLAGS) $(LIBDIRS) $(LIBS) -c $(<) -o $(@) $(LOG_COMPILE)
	@$(ECHO) " CPP    $<"; $(CXX) $(CPLUSFLAGS) -O3 -c $(<) -o $(@) $(LOG_COMPILE)
	@$(LOG_CPP_FOOTER)
				
$(BIN_TARGET):: $(OBJS)
#	@$(ECHO) " LD     $(BIN_TARGET)    " | $(TEE) -a link.log; $(LD) $(LIBDIRS) $(LIBS) $(OBJS) -o eTestbed
	$(CXX) -o $@ $(OBJS) $(LDFLAGS)
	
#$(LIB_TARGET):: $(OBJS)
#	@$(RM) -f $@
#	@$(ECHO) " AR     $@   " | $(TEE) -a link.log; $(AR)     $@ $(OBJS) $(LOG_LINK)
#	@$(ECHO) " RANLIB $@   " | $(TEE) -a link.log; $(RANLIB) $@         $(LOG_LINK)

#$(SHARED_LIB_TARGET):: $(LIB_TARGET)
#	@$(ECHO) " LD     $(SHARED_LIB_TARGET)   " | $(TEE) -a link.log; $(LD) -shared -whole-archive $(LIB_TARGET) -o $(SHARED_LIB_TARGET) $(LOG_LINK)

clean-local::
	@$(ECHO) " CLEAN   "; $(RM) -f $(TARGETS) Makefile.bak core[0-9]* *_pure_*.o *.s *~ $(LOG_MAKE);
	@if [ -f core ]; then $(RM) -f core; fi;

# get global rules
#include ../../Rules.make
include ../Rules.make

# include generated dependencies
-include .depend

# setup logging rules
include Rules.logs

